package com.xianyun.site.support.executor.filter.support;

import com.xianyun.common.core.constant.Constants;
import com.xianyun.common.core.filter.Filter;
import com.xianyun.common.core.filter.FilterInvoker;
import com.xianyun.common.core.utils.DateToolUtils;
import com.xianyun.site.support.common.exception.SupportErrorCode;
import com.xianyun.site.support.common.exception.SupportException;
import com.xianyun.site.support.domain.model.ReceiveMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author mac_zyj
 */
@Slf4j
@Component
public class OverdueFilter implements Filter<ReceiveMessage> {
    @Override
    public void doFilter(ReceiveMessage context, FilterInvoker nextFilter) {
        if (null!=context.getCurrentTime()){
            if (DateToolUtils.getDateMinPoor(DateToolUtils.getNowDate(),context.getCurrentTime())> Constants.CAPTCHA_EXPIRATION){
                log.info("过期消息----初始拦截--- ---弃用--"+context.getCurrentTime()+"-事务编号----"+context.getTransactionId());
                throw new SupportException(SupportErrorCode.BIZ_MQ_OVERDUE,"过期消息");
            }
        }
        nextFilter.invoke(context);
    }
}
